
/*********************************************************************************************
 *
 *			Function to get the input from the buffer 										 *
 *
 ********************************************************************************************/



#include "mystrings.h"


int  get_string (char *line, char ** string){    /* procedure for geting string from line */

	char * start ;					/* ptr to store the starting address */
	char *temp ;
	int count  = 0;					/* count to allocate memory */
	int flag = 0;

	for  ( ; *line == ' ' || *line == '\t' ; line++)  /* skip the white spaces */
		;
	start = line ;
	for ( ; *line ; line++)							 /* eleminating the new line */
		if ( *line == '\n'){
			*line = '\0' ;
		}

	line = start ;
	while (*line){									/* check for the vaild character */
		if  (*line >=32 && *line <= 126 ){
			count++;
			flag = 1;
		}
		else {
			flag = 0;
			break ;
		}
		line++;
	}
	if (flag == 0 ){								/* failure */
		return 0 ;
	}
	else {
		line = start;								/* create memory and copy the string */
		temp  = (char*) malloc ( MAXLINE *sizeof (char ) ) ;
		if  ( temp != '\0')
			start = temp ;
		while ( *line != '\0'){
			*temp++ = *line++;
		}
		*string = start ;
		return 1;
	}
}


